package com.yootoo.bsuser;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.yootoo.common.exception.BizException;
import com.yootoo.common.exception.ParamException;
import com.yootoo.common.exception.ProjException;
import com.yootoo.common.responseVo.ResultBean;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class SysExceptionHandler {
	
    @ExceptionHandler(value = Exception.class)
    public ResultBean<String> defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {

       ResultBean<String> r = new ResultBean<>(e);	
    	
        return r;
    }

    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public ResultBean<String> jsonErrorHandler(HttpServletRequest req, BizException e) throws Exception {
    	
    	ResultBean<String> r = new ResultBean<>(e);	
    	
        return r;
    }
    
    
    @ExceptionHandler(value = ParamException.class)
    @ResponseBody
    public ResultBean<String> jsonErrorHandler(HttpServletRequest req, ParamException e) throws Exception {
    	
    	ResultBean<String> r = new ResultBean<>(e);	
    	
        return r;
    }
    
    @ExceptionHandler(value = ProjException.class)
    @ResponseBody
    public ResultBean<String> jsonErrorHandler(HttpServletRequest req, ProjException e) throws Exception {
    	
    	ResultBean<String> r = new ResultBean<>(e);	
    	
        return r;
    }

}